import { drizzle } from "drizzle-orm/libsql";
import { sql } from "drizzle-orm"; // 导入 sql 辅助函数
import { createClient } from "@libsql/client";
import * as schema from "./auth-schema";

const client = createClient({ url: process.env.DATABASE_URL || "" });

const turso = createClient({
  url: process.env.TURSO_DATABASE_URL!,
  authToken: process.env.TURSO_AUTH_TOKEN,
});

export const db = drizzle({
  client,
  schema,
});

// 测试查询（使用 sql 辅助函数）
async function testQuery() {
  try {
    // 对于较新的 Drizzle 版本，推荐使用 sql 模板字符串
    const result = await db.run(sql`select 1`);
    console.log("查询成功:", result);
  } catch (error) {
    console.error("查询失败:", error);
  }
}

testQuery();
